#include<iostream>
#include<algorithm>
using namespace std;

int a[100000], l, r;

void bs(int x) {
    int m = 1 << 31;
    while(l<=r) {
        int mid = (l+r) >> 1;
        if (abs(a[mid]-x) < abs(m-x)) {
            m = a[mid];
        } else if(abs(a[mid]-x) == abs(m-x)) {
            m = min(a[mid], m);
        }
        if(x > a[mid]) {
            l = mid + 1;
        } else if(x < a[mid]) {
            r = mid - 1;
        } else {
            m = a[mid];
            break;
        }
    }
    cout << m << endl;
}

int main() {
    int n, m;
    cin >> n;
    for (int i=0; i<n; i++) {
        cin >> a[i];
    }
    cin >> m;
    while(m--) {
        int x;
        cin >> x;
        l = 0;
        r = n - 1;
        bs(x);
    }
    return 0;
}